<!-- build time:Tue Jul 21 2020 12:41:25 GMT+0800 (GMT+08:00) --><!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=2"><meta name="theme-color" content="#222"><meta name="generator" content="Hexo 4.2.0"><link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png"><link rel="icon" type="image/png" sizes="32x32" href="/img/blog_favicon/favicon-32x32-next.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/blog_favicon/favicon-16x16-next.png"><link rel="mask-icon" href="/images/logo.svg" color="#222"><meta name="baidu-site-verification" content="r15J5zOS2KI43yBS"><link rel="stylesheet" href="/css/main.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"><link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/themes/blue/pace-theme-minimal.min.css"><script src="//cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.min.js"></script><script id="hexo-configurations">var NexT=window.NexT||{},CONFIG={hostname:new URL("http://www.zhengjiaao.cn").hostname,root:"/",scheme:"Muse",version:"7.6.0",exturl:!1,sidebar:{position:"left",display:"post",padding:18,offset:12,onmobile:!1},copycode:{enable:!0,show_result:!0,style:null},back2top:{enable:!0,sidebar:!1,scrollpercent:!0},bookmark:{enable:!0,color:"#222",save:"auto"},fancybox:!0,mediumzoom:!1,lazyload:!1,pangu:!1,comments:{style:"tabs",active:"valine",storage:!0,lazyload:!1,nav:null,activeClass:"valine"},algolia:{appID:"",apiKey:"",indexName:"",hits:{per_page:10},labels:{input_placeholder:"Search for Posts",hits_empty:"We didn't find any results for the search: ${query}",hits_stats:"${hits} results found in ${time} ms"}},localsearch:{enable:!0,trigger:"auto",top_n_per_article:1,unescape:!1,preload:!1},path:"search.xml",motion:{enable:!0,async:!1,transition:{post_block:"fadeIn",post_header:"slideDownIn",post_body:"slideDownIn",coll_header:"slideLeftIn",sidebar:"slideUpIn"}}}</script><meta property="og:type" content="article"><meta property="og:title" content="Linux版-jenkins自动化部署"><meta property="og:url" content="http://www.zhengjiaao.cn/posts/3858457734.html"><meta property="og:site_name" content="宇宙小神特别萌"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-87fb57869a921eff.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-55a7becc07eba099.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-8759b950b505802e.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-2bc39b3922a0ef79.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-217fab5b50dcbcdd.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-e89356e68b5edfa1.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-5245a746f443f283.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-0ceca14d6d43492b.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-6b9e1125a60f9312.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-faa9a49c60e854d5.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-b05fc473902fa20d.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-745a11c796b45b3a.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-35834b4111c55782.png"><meta property="article:published_time" content="2020-01-03T08:14:49.000Z"><meta property="article:modified_time" content="2020-07-20T10:37:55.292Z"><meta property="article:author" content="宇宙小神特别萌"><meta property="article:tag" content="Jenkins"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/15645795-87fb57869a921eff.png"><link rel="canonical" href="http://www.zhengjiaao.cn/posts/3858457734.html"><script id="page-configurations">CONFIG.page={sidebar:"",isHome:!1,isPost:!0}</script><title>Linux版-jenkins自动化部署 | 宇宙小神特别萌</title><noscript><style>.sidebar-inner,.use-motion .brand,.use-motion .collection-header,.use-motion .comments,.use-motion .menu-item,.use-motion .pagination,.use-motion .post-block,.use-motion .post-body,.use-motion .post-header{opacity:initial}.use-motion .site-subtitle,.use-motion .site-title{opacity:initial;top:initial}.use-motion .logo-line-before i{left:initial}.use-motion .logo-line-after i{right:initial}</style></noscript><link rel="alternate" href="/atom.xml" title="宇宙小神特别萌" type="application/atom+xml"></head><body itemscope itemtype="http://schema.org/WebPage"><div class="container use-motion"><div class="headband"></div><header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="header-inner"><div class="site-brand-container"><div class="site-meta custom-logo"><div class="site-meta-headline"><a><img class="custom-logo-image" src="/img/blog_favicon/favicon-32x32-next.png" alt="宇宙小神特别萌"></a></div><div><a href="/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title">宇宙小神特别萌</span> <span class="logo-line-after"><i></i></span></a></div><p class="site-subtitle">ZhengJa</p></div><div class="site-nav-toggle"><div class="toggle" aria-label="切换导航栏"><span class="toggle-line toggle-line-first"></span> <span class="toggle-line toggle-line-middle"></span> <span class="toggle-line toggle-line-last"></span></div></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">27</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">116</span></a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a></li><li class="menu-item menu-item-messageboard"><a href="/messageboard/" rel="section"><i class="fa fa-fw fa-address-book"></i>留言板</a></li><li class="menu-item menu-item-links"><a href="/links/" rel="section"><i class="fa fa-fw fa-user-plus"></i>友链</a></li><li class="menu-item menu-item-shuoshuo"><a href="/shuoshuo/" rel="section"><i class="fa fa-fw fa-file-text-o"></i>说说</a></li><li class="menu-item menu-item-search"><a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索</a></li></ul></nav><div class="site-search"><div class="popup search-popup"><div class="search-header"><span class="search-icon"><i class="fa fa-search"></i></span><div class="search-input-container"><input autocomplete="off" autocorrect="off" autocapitalize="none" placeholder="搜索..." spellcheck="false" type="text" id="search-input"></div><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span></div><div id="search-result"></div></div><div class="search-pop-overlay"></div></div></div></header><div class="back-to-top"><i class="fa fa-arrow-up"></i> <span>0%</span></div><div class="reading-progress-bar"></div><a role="button" class="book-mark-link book-mark-link-fixed"></a> <a href="https://github.com/zhengjiaao" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin:130px 106px" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><main class="main"><div class="main-inner"><div class="content-wrap"><div class="content"><div class="posts-expand"><article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN"><link itemprop="mainEntityOfPage" href="http://www.zhengjiaao.cn/posts/3858457734.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="image" content="/my-images/avatar.gif"><meta itemprop="name" content="宇宙小神特别萌"><meta itemprop="description" content="人生就是一次幸运的旅行！"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="宇宙小神特别萌"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">Linux版-jenkins自动化部署</h1><div class="post-meta"><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建时间：2020-01-03 16:14:49" itemprop="dateCreated datePublished" datetime="2020-01-03T16:14:49+08:00">2020-01-03</time> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-calendar-check-o"></i> </span><span class="post-meta-item-text">更新于</span> <time title="修改时间：2020-07-20 18:37:55" itemprop="dateModified" datetime="2020-07-20T18:37:55+08:00">2020-07-20</time> </span><span id="/posts/3858457734.html" class="post-meta-item leancloud_visitors" data-flag-title="Linux版-jenkins自动化部署" title="热度"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">热度：</span> <span class="leancloud-visitors-count"></span> <span>℃</span> </span><span class="post-meta-item" title="热度" id="busuanzi_container_page_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">热度：</span> <span id="busuanzi_value_page_pv"></span> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-comment-o"></i> </span><span class="post-meta-item-text">Valine：</span> <a title="valine" href="/posts/3858457734.html#comments" itemprop="discussionUrl"><span class="post-comments-count valine-comment-count" data-xid="/posts/3858457734.html" itemprop="commentCount"></span></a></span><br><span class="post-meta-item" title="本文字数"><span class="post-meta-item-icon"><i class="fa fa-file-word-o"></i> </span><span class="post-meta-item-text">本文字数：</span> <span>15k</span> </span><span class="post-meta-item" title="阅读时长"><span class="post-meta-item-icon"><i class="fa fa-clock-o"></i> </span><span class="post-meta-item-text">阅读时长 &asymp;</span> <span>14 分钟</span></span></div></header><div class="post-body" itemprop="articleBody"><meta name="referrer" content="no-referrer"><a id="more"></a><p><img src="https://upload-images.jianshu.io/upload_images/15645795-87fb57869a921eff.png" alt="Linux版 jenkins自动化部署目录.png"></p><p><strong>注意：本片配置：jenkins服务器和应用服务器不在同一台机器上 ，且应用服务器 负责流执行程 （推荐）。</strong><br><strong>流程：代码上传-&gt;gitlab通知-&gt;jenkins服务器执行构建-&gt;远程应用服务器git下拉-&gt;远程应用服务器maven打包-&gt;发送到远程应用服务器的tomcat-&gt;发布</strong></p><p>以下是配置说明：<br>需要两台服务器：一台部署jenkins服务器、另一台部署应用服务器。<br>要求：两台服务器可以互相通信。<br>部署jenkins服务器(Linux1): jdk、jenkins、tomcat(可选,但不推荐)<br>部署应用服务器(Linux2): jdk、git、maven、tomcat</p><blockquote><p>说明一下：部署的jenkins服务器可以是内网本地 ，应用服务器可以是外网环境的云服务器。Jenkins也是可以实现手动或轮询的方式构建到应用服务器的 ，但 ，不能使用gitlab通知jenkins自动构建 ，因 ，gitlab找不到你的内网地址。</p></blockquote><h2 id="一、部署jenkins服务器-Linux1"><a href="#一、部署jenkins服务器-Linux1" class="headerlink" title="一、部署jenkins服务器(Linux1)"></a>一、部署jenkins服务器(Linux1)</h2><h3 id="1、安装jdk1-8"><a href="#1、安装jdk1-8" class="headerlink" title="1、安装jdk1.8"></a>1、安装jdk1.8</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install java</span><br></pre></td></tr></table></figure><h3 id="2、安装jenkins"><a href="#2、安装jenkins" class="headerlink" title="2、安装jenkins"></a>2、安装jenkins</h3><p>前提环境：jdk1.8<br>下载地址：<a href="http://mirrors.jenkins.io/war-stable/latest/jenkins.war" target="_blank" rel="noopener">jenkins.war</a> 稳定版</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_11_centos ~]# ls</span><br><span class="line">jdk1.8  jdk-8u221-linux-x64.tar.gz  jenkins.war</span><br><span class="line">[root@VM_0_11_centos ~]# java -jar jenkins.war</span><br></pre></td></tr></table></figure><p>访问：ip:8080<br><a href="http://49.235.71.163:8080/" target="_blank" rel="noopener">http://49.235.71.163:8080</a><br>创建用户：admin/admin 用户名：zhengja</p><h4 id="2-1jenkins-插件安装-推荐"><a href="#2-1jenkins-插件安装-推荐" class="headerlink" title="2.1jenkins 插件安装(推荐)"></a>2.1jenkins 插件安装(推荐)</h4><blockquote><p>Safe Restart 方便重启jenkins ，每次配置jenkins需要重启让配置生效<br>Rebuilder 方便重新构建<br>Git Parameters 确定构建哪个分支</p></blockquote><h4 id="2-2jenkins-基础配置"><a href="#2-2jenkins-基础配置" class="headerlink" title="2.2jenkins 基础配置"></a>2.2jenkins 基础配置</h4><ul><li>安全性配置<ul><li>系统管理-&gt;全局安全配置:<br><img src="https://upload-images.jianshu.io/upload_images/15645795-55a7becc07eba099.png" alt="admin.png"><blockquote><p>1.去掉 允许用户注册<br>2.选用 安全矩阵 -&gt;Add user or group… -&gt;输入刚创建的admin ，赋予全部权限 ，保存</p></blockquote></li></ul></li></ul><h2 id="二、部署应用服务器-Linux2"><a href="#二、部署应用服务器-Linux2" class="headerlink" title="二、部署应用服务器(Linux2)"></a>二、部署应用服务器(Linux2)</h2><p>环境: jdk1.8 ，git ，maven ，tomcat8</p><h3 id="1-，开启ssh"><a href="#1-，开启ssh" class="headerlink" title="1 ，开启ssh"></a>1 ，开启ssh</h3><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos ~]# netstat -anp|grep :<span class="number">22</span></span><br><span class="line">tcp        <span class="number">0</span>      <span class="number">0</span> <span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span>:<span class="number">22</span>              <span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span>:*            </span><br><span class="line">tcp        <span class="number">0</span>     <span class="number">36</span> <span class="number">172</span>.<span class="number">16</span>.<span class="number">0</span>.<span class="number">6</span>:<span class="number">22</span>           <span class="number">211</span>.<span class="number">161</span>.<span class="number">248</span>.<span class="number">60</span>:<span class="number">22447</span> </span><br><span class="line">[root@VM_0_6_centos ~]# service sshd <span class="built_in">start</span></span><br><span class="line">Redirecting to /bin/systemctl <span class="built_in">start</span> sshd.service</span><br></pre></td></tr></table></figure><h3 id="2-，关闭防火墙-内网环境相对安全"><a href="#2-，关闭防火墙-内网环境相对安全" class="headerlink" title="2 ，关闭防火墙(内网环境相对安全)"></a>2 ，关闭防火墙(内网环境相对安全)</h3><p>安装iptables<br>如果你要改用iptables的话 ，需要安装iptables服务：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">#安装</span><br><span class="line">sudo yum install iptables-services </span><br><span class="line">#开启iptables</span><br><span class="line">sudo systemctl enable iptables </span><br><span class="line">sudo systemctl enable ip6tables </span><br><span class="line">#启动服务</span><br><span class="line">sudo systemctl <span class="built_in">start</span> iptables </span><br><span class="line">sudo systemctl <span class="built_in">start</span> ip6tables</span><br></pre></td></tr></table></figure><p>关闭防火墙:</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos ~]# service iptables stop</span><br><span class="line">Redirecting to /bin/systemctl stop iptables.service</span><br><span class="line">[root@VM_0_6_centos ~]# service iptables status</span><br><span class="line">Redirecting to /bin/systemctl status iptables.service</span><br><span class="line">● iptables.service - IPv4 firewall with iptables</span><br><span class="line"><span class="function">   Loaded: <span class="title">loaded</span> (/<span class="title">usr</span>/<span class="title">lib</span>/<span class="title">systemd</span>/<span class="title">system</span>/<span class="title">iptables.service</span>; <span class="title">enabled</span>; <span class="title">vendor</span> <span class="title">preset</span>: <span class="title">disabled</span>)</span></span><br><span class="line"><span class="function">   <span class="title">Active</span>: <span class="title">inactive</span> (<span class="title">dead</span>) <span class="title">since</span> <span class="title">Thu</span> 2019-09-26 21:28:33 <span class="title">CST</span>; 6<span class="title">s</span> <span class="title">ago</span></span></span><br><span class="line"><span class="function">  <span class="title">Process</span>: 9537 <span class="title">ExecStop</span>=/<span class="title">usr</span>/<span class="title">libexec</span>/<span class="title">iptables</span>/<span class="title">iptables.init</span> <span class="title">stop</span> (<span class="title">code</span>=<span class="title">exited</span>, <span class="title">status</span>=0/<span class="title">SUCCESS</span>)</span></span><br><span class="line"><span class="function">  <span class="title">Process</span>: 9354 <span class="title">ExecStart</span>=/<span class="title">usr</span>/<span class="title">libexec</span>/<span class="title">iptables</span>/<span class="title">iptables.init</span> <span class="title">start</span> (<span class="title">code</span>=<span class="title">exited</span>, <span class="title">status</span>=0/<span class="title">SUCCESS</span>)</span></span><br><span class="line"><span class="function"> <span class="title">Main</span> <span class="title">PID</span>: 9354 (<span class="title">code</span>=<span class="title">exited</span>, <span class="title">status</span>=0/<span class="title">SUCCESS</span>)</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Sep</span> 26 21:27:28 <span class="title">VM_0_6_centos</span> <span class="title">systemd</span>[1]: <span class="title">Starting</span> <span class="title">IPv4</span> <span class="title">firewall</span> <span class="title">with</span> <span class="title">iptables</span>...</span></span><br><span class="line"><span class="function"><span class="title">Sep</span> 26 21:27:28 <span class="title">VM_0_6_centos</span> <span class="title">iptables.init</span>[9354]: <span class="title">iptables</span>: <span class="title">Applying</span> <span class="title">firewall</span> <span class="title">rules</span>: [  <span class="title">OK</span>  ]</span></span><br><span class="line"><span class="function"><span class="title">Sep</span> 26 21:27:28 <span class="title">VM_0_6_centos</span> <span class="title">systemd</span>[1]: <span class="title">Started</span> <span class="title">IPv4</span> <span class="title">firewall</span> <span class="title">with</span> <span class="title">iptables</span>.</span></span><br><span class="line"><span class="function"><span class="title">Sep</span> 26 21:28:33 <span class="title">VM_0_6_centos</span> <span class="title">systemd</span>[1]: <span class="title">Stopping</span> <span class="title">IPv4</span> <span class="title">firewall</span> <span class="title">with</span> <span class="title">iptables</span>...</span></span><br><span class="line"><span class="function"><span class="title">Sep</span> 26 21:28:33 <span class="title">VM_0_6_centos</span> <span class="title">iptables.init</span>[9537]: <span class="title">iptables</span>: <span class="title">Setting</span> <span class="title">chains</span> <span class="title">to</span> <span class="title">policy</span> <span class="title">ACCEPT</span>: <span class="title">filte</span>...  ]</span></span><br><span class="line"><span class="function"><span class="title">Sep</span> 26 21:28:33 <span class="title">VM_0_6_centos</span> <span class="title">iptables.init</span>[9537]: <span class="title">iptables</span>: <span class="title">Flushing</span> <span class="title">firewall</span> <span class="title">rules</span>: [  <span class="title">OK</span>  ]</span></span><br><span class="line"><span class="function"><span class="title">Sep</span> 26 21:28:33 <span class="title">VM_0_6_centos</span> <span class="title">systemd</span>[1]: <span class="title">Stopped</span> <span class="title">IPv4</span> <span class="title">firewall</span> <span class="title">with</span> <span class="title">iptables</span>.</span></span><br><span class="line"><span class="function"><span class="title">Hint</span>: <span class="title">Some</span> <span class="title">lines</span> <span class="title">were</span> <span class="title">ellipsized</span>, <span class="title">use</span> -<span class="title">l</span> <span class="title">to</span> <span class="title">show</span> <span class="title">in</span> <span class="title">full</span>.</span></span><br><span class="line"><span class="function">[<span class="title">root</span>@<span class="title">VM_0_6_centos</span> ~]#</span></span><br></pre></td></tr></table></figure><blockquote><p>Stopped IPv4 firewall with iptables 说明防火墙已关闭</p></blockquote><h3 id="2-，安装-jdk"><a href="#2-，安装-jdk" class="headerlink" title="2 ，安装 jdk"></a>2 ，安装 jdk</h3><h4 id="2-1-方式一：普通安装方式：-下载慢"><a href="#2-1-方式一：普通安装方式：-下载慢" class="headerlink" title="2.1 方式一：普通安装方式：(下载慢)"></a>2.1 方式一：普通安装方式：(下载慢)</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">yum install java</span><br><span class="line">java -version</span><br></pre></td></tr></table></figure><h4 id="2-2-方式二：安装指定版本：java1-8（下载慢）"><a href="#2-2-方式二：安装指定版本：java1-8（下载慢）" class="headerlink" title="2.2 方式二：安装指定版本：java1.8（下载慢）"></a>2.2 方式二：安装指定版本：java1.8（下载慢）</h4><ul><li>在线下载jdk (下载比较慢)</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget --no-check-certificate --no-cookies --header &quot;Cookie: oraclelicense&#x3D;accept-securebackup-cookie&quot;  http:&#x2F;&#x2F;download.oracle.com&#x2F;otn-pub&#x2F;java&#x2F;jdk&#x2F;8u131-b11&#x2F;d54c1d3a095b4ff2b6607d096fa80163&#x2F;jdk-8u131-linux-x64.rpm</span><br></pre></td></tr></table></figure><ul><li>赋权限</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod +x jdk-8u131-linux-x64.rpm</span><br></pre></td></tr></table></figure><ul><li>进行安装</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -ivh jdk-8u131-linux-x64.rpm</span><br></pre></td></tr></table></figure><ul><li>查看是否安装成功</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">java -version</span><br></pre></td></tr></table></figure><p>默认安装路径为 /usr/java/jdk1.8.0_131</p><ul><li>编辑环境变量</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim &#x2F;etc&#x2F;profile</span><br></pre></td></tr></table></figure><p>环境变量为</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">export JAVA_HOME&#x3D;&#x2F;usr&#x2F;java&#x2F;jdk1.8.0_131</span><br><span class="line">export PATH&#x3D;$JAVA_HOME&#x2F;bin:$PATH </span><br><span class="line">export CLASSPATH&#x3D;.:$JAVA_HOME&#x2F;lib&#x2F;dt.jar:$JAVA_HOME&#x2F;lib&#x2F;tools.jar</span><br></pre></td></tr></table></figure><ul><li>使得配置立即生效</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">source &#x2F;etc&#x2F;profile</span><br></pre></td></tr></table></figure><ul><li>查看是否安装成功</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">javac</span><br><span class="line">java -version</span><br><span class="line">echo $PATH</span><br></pre></td></tr></table></figure><h4 id="2-3-方式三：下载jdk1-8上传linux服务器-安装快-推荐"><a href="#2-3-方式三：下载jdk1-8上传linux服务器-安装快-推荐" class="headerlink" title="2.3 方式三：下载jdk1.8上传linux服务器(安装快-推荐)"></a>2.3 方式三：下载jdk1.8上传linux服务器(安装快-推荐)</h4><p>下载：jdk-8u221-linux-x64.tar.gz<br>放到 /usr/local ，解压</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -zxvf jdk-<span class="number">8</span>u221-linux-x64.tar.gz</span><br></pre></td></tr></table></figure><p>改名 jdk1.8</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mv jdk1.8.0_221 jdk1.8</span><br></pre></td></tr></table></figure><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos local]# ls</span><br><span class="line">bin  etc  games  include  jdk1.8  lib  lib64  libexec  qcloud  sbin  share  src  yd.socket.server</span><br></pre></td></tr></table></figure><p>配置jdk1.8环境变量</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos jdk1.8]# pwd</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;jdk1.8</span><br><span class="line">[root@VM_0_6_centos jdk1.8]# vi &#x2F;etc&#x2F;profile</span><br></pre></td></tr></table></figure><p>环境变量为</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">export JAVA_HOME&#x3D;&#x2F;usr&#x2F;local&#x2F;jdk1.8</span><br><span class="line">export PATH&#x3D;$JAVA_HOME&#x2F;bin:$PATH </span><br><span class="line">export CLASSPATH&#x3D;.:$JAVA_HOME&#x2F;lib&#x2F;dt.jar:$JAVA_HOME&#x2F;lib&#x2F;tools.jar</span><br></pre></td></tr></table></figure><p>退出文件 ，保存<br>按Esc键 输入:wq 保存并退出<br>让配置文件生效:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos jdk1.8]# source &#x2F;etc&#x2F;profile</span><br></pre></td></tr></table></figure><p>查看是否配置成功:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos jdk1.8]# java -version</span><br><span class="line">java version &quot;1.8.0_221&quot;</span><br></pre></td></tr></table></figure><p>若出现jdk版本号 ，则安装并配置环境变量成功<br>如果提示命令找不到的话 ，查看一下jdk的配置路径是否错误。<br>删除安装包(可选)：rm -rf jdk-8u221-linux-x64.tar.gz</p><h3 id="3、安装-git"><a href="#3、安装-git" class="headerlink" title="3、安装 git"></a>3、安装 git</h3><h4 id="方式一：git安装（旧版本）"><a href="#方式一：git安装（旧版本）" class="headerlink" title="方式一：git安装（旧版本）"></a>方式一：git安装（旧版本）</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos local]# yum install git</span><br><span class="line">[root@VM_0_6_centos local]# git --version</span><br><span class="line">git version 1.8.3.1</span><br></pre></td></tr></table></figure><h4 id="方式二：gti安装-最新版本—推荐"><a href="#方式二：gti安装-最新版本—推荐" class="headerlink" title="方式二：gti安装(最新版本—推荐)"></a>方式二：gti安装(最新版本—推荐)</h4><p>1、获取<a href="https://github.com/git/git/releases" target="_blank" rel="noopener">github</a>最新的Git安装包下载链接 ，下载新版本 <a href="https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz" target="_blank" rel="noopener">git-2.9.5.tar.gz</a> 上传到linux；<br>2、压缩包解压:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo tar -zxvf git-2.9.5.tar.gz</span><br></pre></td></tr></table></figure><p>3、进入解压后的文件夹：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cd git-2.9.5</span><br></pre></td></tr></table></figure><p>4、执行编译：耐心等待编译即可</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make prefix&#x3D;&#x2F;usr&#x2F;local&#x2F;git all</span><br></pre></td></tr></table></figure><p>5、安装Git至/usr/local/git路径 ，命令为</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make prefix&#x3D;&#x2F;usr&#x2F;local&#x2F;git install</span><br></pre></td></tr></table></figure><p>6、打开环境变量配置文件 ，命令 ，在底部加上Git相关配置信息：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim &#x2F;etc&#x2F;profile</span><br></pre></td></tr></table></figure><blockquote><p>PATH=$PATH:/usr/local/git/bin<br>export PATH</p></blockquote><p>然后wq保存 ，退出！<br>让配置文件生效:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">source &#x2F;etc&#x2F;profile</span><br></pre></td></tr></table></figure><p>7、输入命令 git –version ，查看安装的git版本 ，校验通过 ，安装成功。<br>8、删除安装包(可选)：rm -rf git-2.9.5.tar.gz<br>9、查看git安装路径：<br>Linux-如果不清楚自己的Git安装在哪个路径下 ，终端执行</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">whereis git</span><br></pre></td></tr></table></figure><p>配置：/usr/local/git/bin/git</p><h4 id="生成ssh密钥-配置git"><a href="#生成ssh密钥-配置git" class="headerlink" title="生成ssh密钥 配置git"></a>生成ssh密钥 配置git</h4><p>ssh公钥可以配置gitlab、github等 ，<br>ssh私钥可配置jenkins凭证等。<br>用户和邮箱不要求真实</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos ~]<span class="comment"># git config --global user.name "zhengja"</span></span><br><span class="line">[root@VM_0_6_centos ~]<span class="comment"># git config --global user.email "zhengja@dist.com"</span></span><br><span class="line">[root@VM_0_6_centos ~]<span class="comment"># ssh-keygen -t rsa -C "zhengja@dist.com"</span></span><br><span class="line">Enter file <span class="keyword">in</span> which to save the key (/root/.ssh/id_rsa):</span><br><span class="line">Generating public/private rsa key pair.</span><br><span class="line">Enter file <span class="keyword">in</span> which to save the key (/root/.ssh/id_rsa): </span><br><span class="line">Enter passphrase (empty <span class="keyword">for</span> no passphrase): </span><br><span class="line">Enter same passphrase again: </span><br><span class="line">Your identification has been saved <span class="keyword">in</span> /root/.ssh/id_rsa.</span><br><span class="line">Your public key has been saved <span class="keyword">in</span> /root/.ssh/id_rsa.pub.</span><br><span class="line">The key fingerprint <span class="keyword">is</span>:</span><br><span class="line">SHA256:EqKVJUBpxVYpswJifGiXyplLTUcBYFNaMxaODZQPUmc zhengja@dist.com</span><br><span class="line">The key<span class="string">'s randomart image is:</span></span><br><span class="line"><span class="string">+---[RSA 2048]----+</span></span><br><span class="line"><span class="string">|oOO&amp;E++.         |</span></span><br><span class="line"><span class="string">|=B%BB=.          |</span></span><br><span class="line"><span class="string">|*=@+=+.          |</span></span><br><span class="line"><span class="string">| *.=.. .         |</span></span><br><span class="line"><span class="string">|. o.  . S        |</span></span><br><span class="line"><span class="string">| .     .         |</span></span><br><span class="line"><span class="string">|                 |</span></span><br><span class="line"><span class="string">|                 |</span></span><br><span class="line"><span class="string">|                 |</span></span><br><span class="line"><span class="string">+----[SHA256]-----+</span></span><br></pre></td></tr></table></figure><p>拿到公钥配置gitlab</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos local]# cd &#x2F;root&#x2F;.ssh&#x2F;</span><br><span class="line">[root@VM_0_6_centos .ssh]# ls</span><br><span class="line">authorized_keys  id_rsa  id_rsa.pub  known_hosts</span><br><span class="line">[root@VM_0_6_centos .ssh]# vim id_rsa.pub</span><br></pre></td></tr></table></figure><blockquote><p>ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDcArp9fBpi7CWJ50dQQTHbLfRkMyhVuox7bFEeYu3kaFYO3ECInfiBEK8PdYAKPjGWRirYQGCBQlsSzGd4F3sVTQH4ePk0bk/iAwnZsgOBgMgyZW6c00u+afJ/h8PNRK2xr60kB3n4no4UDov4hsuGdCKhavrHRzs3s6H+b7WKxILdSwZ7BpduGZGCOug8JtcnwF1mmMKi0YH0KrIxnrOR9GHT+wHAyJ5WjYU4Xzr+ZIGN6MfrM7X99y/uyMsrv8nzliMxWpFxduYAkKkfrqf46Y18oZfn5VdXhfnvyd+FqWTPdtJF2EZtKdhwGnouuyTdESQP3PPacFM1ZeW58R/T <a href="mailto:zhengja@dist.com">zhengja@dist.com</a></p></blockquote><p><img src="https://upload-images.jianshu.io/upload_images/15645795-8759b950b505802e.png" alt="gitlab 配置公钥.png"><br>测试：<br><img src="https://upload-images.jianshu.io/upload_images/15645795-2bc39b3922a0ef79.png" alt="gitlab 配置公钥测试.png"></p><p>测试：git命令克隆sshUrl到本地</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone sshURL</span><br></pre></td></tr></table></figure><h3 id="4、安装-maven"><a href="#4、安装-maven" class="headerlink" title="4、安装 maven"></a>4、安装 maven</h3><p>下载 <a href="http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.zip" target="_blank" rel="noopener">apache-maven-3.6.2-bin.zip</a> ，上传到linux系统并解压</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos local]# ls</span><br><span class="line">apache-maven-3.6.2-bin.zip  etc    include  lib    libexec  sbin   src</span><br><span class="line">bin                         games  jdk1.8   lib64  qcloud   share  yd.socket.server</span><br><span class="line">[root@VM_0_6_centos local]# unzip apache-maven-3.6.2-bin.zip </span><br><span class="line">[root@VM_0_6_centos local]# ls</span><br><span class="line">apache-maven-3.6.2          bin  games    jdk1.8  lib64    qcloud  share  yd.socket.server</span><br><span class="line">apache-maven-3.6.2-bin.zip  etc  include  lib     libexec  sbin    src</span><br></pre></td></tr></table></figure><p>配置maven环境变量</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos apache-maven-3.6.2]# pwd</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;apache-maven-3.6.2</span><br><span class="line">[root@VM_0_6_centos apache-maven-3.6.2]# vim &#x2F;etc&#x2F;profile</span><br></pre></td></tr></table></figure><p>末尾添加（路径要正确）</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">export MAVEN_HOME&#x3D;&#x2F;usr&#x2F;local&#x2F;apache-maven-3.6.2</span><br><span class="line">export PATH&#x3D;$MAVEN_HOME&#x2F;bin:$PATH</span><br></pre></td></tr></table></figure><p>重新加载配置–&gt;测试maven是否配置成功</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos apache-maven-3.6.2]# . &#x2F;etc&#x2F;profile</span><br><span class="line">[root@VM_0_6_centos apache-maven-3.6.2]# mvn -version</span><br><span class="line">Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T23:06:16+08:00)</span><br><span class="line">Maven home: &#x2F;usr&#x2F;local&#x2F;apache-maven-3.6.2</span><br><span class="line">Java version: 1.8.0_221, vendor: Oracle Corporation, runtime: &#x2F;usr&#x2F;local&#x2F;jdk1.8&#x2F;jre</span><br></pre></td></tr></table></figure><p>删除安装包(可选):rm -rf apache-maven-3.6.2-bin.zip</p><h3 id="5、安装-tomcat"><a href="#5、安装-tomcat" class="headerlink" title="5、安装 tomcat"></a>5、安装 tomcat</h3><p>下载 <a href="http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.46/bin/apache-tomcat-8.5.46.zip" target="_blank" rel="noopener">tomcat8</a> ,上传到linux ，并解压</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos local]# unzip apache-tomcat-8.5.46.zip </span><br><span class="line">[root@VM_0_6_centos local]# ls</span><br><span class="line">apache-maven-3.6.2        bin    include  lib64    sbin   yd.socket.server</span><br><span class="line">apache-tomcat-8.5.46      etc    jdk1.8   libexec  share</span><br><span class="line">apache-tomcat-8.5.46.zip  games  lib      qcloud   src</span><br></pre></td></tr></table></figure><p>配置tomcat<br>给tomcat下的所有文件授给任何人都可执行的权限</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos local]# cd apache-tomcat-8.5.46&#x2F;</span><br><span class="line">[root@VM_0_6_centos apache-tomcat-8.5.46]# chmod a+x -R *</span><br></pre></td></tr></table></figure><p>修改tomcat端口为8090</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos apache-tomcat-8.5.46]# vim conf&#x2F;server.xml</span><br></pre></td></tr></table></figure><blockquote><p><connector port="8090" protocol="HTTP/1.1" connectiontimeout="20000" redirectport="8443"></connector></p></blockquote><p>启动tomcat：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos apache-tomcat-8.5.46]# bin&#x2F;startup.sh</span><br></pre></td></tr></table></figure><p>查看tomcat是否启动成功</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos apache-tomcat-8.5.46]# ps -ef|grep tomcat</span><br></pre></td></tr></table></figure><blockquote><p>root 22857 1 29 19:12 pts/0 00:00:02 /usr/local/jdk1.8/bin/java -Dcatalina.base=/usr/local/apache-tomcat-8.5.46 -Dcatalina.home=/usr/local/apache-tomcat-8.5.46 -Djava.io.tmpdir=/usr/local/apache-tomcat-8.5.46/temp org.apache.catalina.startup.Bootstrap start<br>root 27474 19080 0 10:10 pts/0 00:00:00 grep –color=auto tomcat</p></blockquote><p>启动成功标识！</p><p>关闭tomcat：<br>首先 ，进入Tomcat下的bin目录</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;usr&#x2F;local&#x2F;tomcat&#x2F;bin</span><br><span class="line">使用.&#x2F;shutdown.sh或者是sh shutdown.sh关闭Tomcat</span><br></pre></td></tr></table></figure><p>想直接直接杀死Tomcat进程（进程号： 22857） ，使用kill命令</p><p>kill -9 22857</p><h2 id="三、jenkins节点Slave配置"><a href="#三、jenkins节点Slave配置" class="headerlink" title="三、jenkins节点Slave配置"></a>三、jenkins节点Slave配置</h2><p>jenkins主机环境：java、jenkins</p><h3 id="1、Linux-的-Slave机器设置"><a href="#1、Linux-的-Slave机器设置" class="headerlink" title="1、Linux 的 Slave机器设置"></a>1、Linux 的 Slave机器设置</h3><p>作为slave的Linux机器为centos系统.<br>ip: 129.204.207.127<br>环境：java1.8、maven、git、tomcat:8090<br>路径：</p><blockquote><p>java : /usr/local/jdk1.8<br>maven : /usr/local/apache-maven-3.6.2<br>git : /usr/local/git<br>tomcat: /usr/local/apache-tomcat-8.5.46</p></blockquote><p>环境变量：vim /etc/profile</p><blockquote><p>export JAVA_HOME=/usr/local/jdk1.8<br>export PATH=$JAVA_HOME/bin:$PATH<br>export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar<br>PATH=$PATH:/usr/local/git/bin<br>export PATH<br>export MAVEN_HOME=/usr/local/apache-maven-3.6.2<br>export PATH=$MAVEN_HOME/bin:$PATH</p></blockquote><p>用户：root/123<br>生成ssh：私钥、公钥 [Linux生成SSH密钥方式](其它/SSH 证书生成(Linux、windows).md)<br>节点Slave生成：authorized_keys 并授权</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos ~]# <span class="built_in">cd</span> .ssh</span><br><span class="line">[root@VM_0_6_centos .ssh]# ls</span><br><span class="line">id_rsa  id_rsa.pub  known_hosts</span><br><span class="line">[root@VM_0_6_centos .ssh]# cat id_rsa.pub &gt; authorized_keys</span><br><span class="line">[root@VM_0_6_centos .ssh]# ls</span><br><span class="line">authorized_keys  id_rsa  id_rsa.pub  known_hosts</span><br><span class="line">[root@VM_0_6_centos .ssh]# chmod <span class="number">700</span> authorized_keys</span><br></pre></td></tr></table></figure><h3 id="2、jenkins配置节点slave凭证"><a href="#2、jenkins配置节点slave凭证" class="headerlink" title="2、jenkins配置节点slave凭证"></a>2、jenkins配置节点slave凭证</h3><p>获取节点Slave私钥：id_rsa</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_6_centos ~]# cd &#x2F;root&#x2F;.ssh</span><br><span class="line">[root@VM_0_6_centos .ssh]# vim id_rsa</span><br></pre></td></tr></table></figure><p>创建节点凭证：root/私钥<br><img src="https://upload-images.jianshu.io/upload_images/15645795-217fab5b50dcbcdd.png" alt="节点配置5.png"></p><p>3、创建节点slave<br>系统管理-&gt;节点管理-&gt;新建节点:<br>节点名称:Linux_127 、 选着固定节点 –&gt;确定<br><img src="https://upload-images.jianshu.io/upload_images/15645795-e89356e68b5edfa1.png" alt="节点配置6.png"></p><p>查看节点列表：显示节点磁盘大小说明配置成功<br><img src="https://upload-images.jianshu.io/upload_images/15645795-5245a746f443f283.png" alt="节点配置7.png"></p><p>测试节点：<br>新建任务：任务名称：springboot-test-gitlab、选择：构建一个自由风格的软件项目<br><img src="https://upload-images.jianshu.io/upload_images/15645795-0ceca14d6d43492b.png" alt="节点配置8.png"><br><img src="https://upload-images.jianshu.io/upload_images/15645795-6b9e1125a60f9312.png" alt="节点配置9.png"><br>执行<strong>立即构建</strong></p><p>控制台输出：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">成功控制台输出</span><br><span class="line">Started by user zhengja</span><br><span class="line">Running as SYSTEM</span><br><span class="line">Building remotely on Linux_127 <span class="keyword">in</span> workspace /root/.jenkins/workspace/springboot-test-gitlab</span><br><span class="line">[springboot-test-gitlab] $ /bin/sh -xe /tmp/jenkins1901112003247678190.sh</span><br><span class="line">+ ifconfig</span><br><span class="line"><span class="function">docker0: <span class="title">flags</span>=4163&lt;<span class="title">UP</span>,<span class="title">BROADCAST</span>,<span class="title">RUNNING</span>,<span class="title">MULTICAST</span>&gt;  <span class="title">mtu</span> 1500</span></span><br><span class="line"><span class="function">        <span class="title">inet</span> 172.17.0.1  <span class="title">netmask</span> 255.255.0.0  <span class="title">broadcast</span> 172.17.255.255</span></span><br><span class="line"><span class="function">        <span class="title">inet6</span> <span class="title">fe80</span>::42:<span class="title">edff:fe35</span>:28<span class="title">c8</span>  <span class="title">prefixlen</span> 64  <span class="title">scopeid</span> 0<span class="title">x20</span>&lt;<span class="title">link</span>&gt;</span></span><br><span class="line"><span class="function">        <span class="title">ether</span> 02:42:<span class="title">ed</span>:35:28:<span class="title">c8</span>  <span class="title">txqueuelen</span> 0  (<span class="title">Ethernet</span>)</span></span><br><span class="line"><span class="function">        <span class="title">RX</span> <span class="title">packets</span> 510  <span class="title">bytes</span> 75763 (73.9 <span class="title">KiB</span>)</span></span><br><span class="line"><span class="function">        <span class="title">RX</span> <span class="title">errors</span> 0  <span class="title">dropped</span> 0  <span class="title">overruns</span> 0  <span class="title">frame</span> 0</span></span><br><span class="line"><span class="function">        <span class="title">TX</span> <span class="title">packets</span> 489  <span class="title">bytes</span> 56366 (55.0 <span class="title">KiB</span>)</span></span><br><span class="line"><span class="function">        <span class="title">TX</span> <span class="title">errors</span> 0  <span class="title">dropped</span> 0 <span class="title">overruns</span> 0  <span class="title">carrier</span> 0  <span class="title">collisions</span> 0</span></span><br><span class="line"><span class="function"><span class="title">group</span> <span class="title">default</span> </span></span><br><span class="line"><span class="function">    <span class="title">link</span>/<span class="title">ether</span> <span class="title">c2</span>:51:<span class="title">e9:ca</span>:47:56 <span class="title">brd</span> <span class="title">ff:ff</span>:<span class="title">ff:ff</span>:<span class="title">ff:ff</span> <span class="title">link</span>-<span class="title">netnsid</span> 0</span></span><br><span class="line"><span class="function">    <span class="title">inet6</span> <span class="title">fe80</span>::<span class="title">c051:e9ff</span>:<span class="title">feca</span>:4756/64 <span class="title">scope</span> <span class="title">link</span> </span></span><br><span class="line"><span class="function">       <span class="title">valid_lft</span> <span class="title">forever</span> <span class="title">preferred_lft</span> <span class="title">forever</span></span></span><br><span class="line"><span class="function"><span class="title">Finished</span>: <span class="title">SUCCESS</span></span></span><br></pre></td></tr></table></figure><blockquote><p><strong>中文解释：</strong></p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">成功控制台输出</span><br><span class="line">由用户zhengja发起</span><br><span class="line">作为系统运行</span><br><span class="line">上远程构建Linux_127在工作区/root/.jenkins/workspace/springboot-test-gitlab</span><br><span class="line">[springboot-test-gitlab] $ / bin / sh -xe /tmp/jenkins1901112003247678190.sh</span><br><span class="line">+ ifconfig</span><br><span class="line">docker0：标志= <span class="number">4163</span> &lt;UP ，BROADCAST ，RUNNING ，MULTICAST&gt; mtu <span class="number">1500</span></span><br><span class="line">        inet <span class="number">172.17</span><span class="number">.0</span><span class="number">.1</span>网络掩码<span class="number">255.255</span><span class="number">.0</span><span class="number">.0</span>广播<span class="number">172.17</span><span class="number">.255</span><span class="number">.255</span></span><br><span class="line">        inet6 fe80 :: <span class="number">42</span>：edff：fe35：<span class="number">28</span>c8 prefixlen <span class="number">64</span> scopeid <span class="number">0x20</span> &lt;link&gt;</span><br><span class="line">        以太网<span class="number">02</span>：<span class="number">42</span>：ed：<span class="number">35</span>：<span class="number">28</span>：c8 txqueuelen <span class="number">0</span>（以太网）</span><br><span class="line">        RX数据包<span class="number">510</span>字节<span class="number">75763</span>（<span class="number">73.9</span> KiB）</span><br><span class="line">        接收错误<span class="number">0</span>掉线<span class="number">0</span>超限<span class="number">0</span>帧<span class="number">0</span></span><br><span class="line">        TX数据包<span class="number">489</span>字节<span class="number">56366</span>（<span class="number">55.0</span> KiB）</span><br><span class="line">        TX错误<span class="number">0</span>掉线<span class="number">0</span>超限<span class="number">0</span>载波<span class="number">0</span>冲突<span class="number">0</span></span><br><span class="line">组默认 </span><br><span class="line">    链接/以太c2：<span class="number">51</span>：e9：ca：<span class="number">47</span>：<span class="number">56</span> brd ff：ff：ff：ff：ff：ff：ff链接netnsid <span class="number">0</span></span><br><span class="line">    inet6 fe80 :: c051：e9ff：feca：<span class="number">4756</span>/<span class="number">64</span>作用域链接 </span><br><span class="line">       永久有效_lft永久首选_lft</span><br><span class="line">已完成：成功</span><br></pre></td></tr></table></figure></blockquote><p><strong>配置节点成功!</strong></p><h2 id="四、创建一个任务-使用节点环境"><a href="#四、创建一个任务-使用节点环境" class="headerlink" title="四、创建一个任务(使用节点环境)"></a>四、创建一个任务(使用节点环境)</h2><p><strong>目的：代码上传-&gt;gitlab通知-&gt;jenkins服务器执行构建-&gt;远程应用服务器git下拉-&gt;远程应用服务器maven打包-&gt;发送到远程应用服务器的tomcat-&gt;发布</strong></p><p>deploy.sh脚本在springboot-test-gitlab/deploy.sh 项目根目录下<br>其中项目中的脚本：deploy.sh</p><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/usr/bin/env bash</span></span><br><span class="line"><span class="comment">#编译+部署项目站点</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#需要配置如下参数</span></span><br><span class="line"><span class="comment"># 项目路径, 在Execute Shell中配置项目路径, pwd 就可以获得该项目路径</span></span><br><span class="line"><span class="comment"># export PROJ_PATH=这个jenkins任务在部署机器上的路径</span></span><br><span class="line"><span class="comment"># export PROJ_PATH=/root/.jenkins</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 输入你的环境上tomcat的全路径</span></span><br><span class="line"><span class="comment"># export TOMCAT_APP_PATH=tomcat在部署机器上的路径</span></span><br><span class="line"><span class="comment"># export TOMCAT_APP_PATH=/usr/local/apache-tomcat-8.5.46</span></span><br><span class="line"></span><br><span class="line"><span class="comment">### base 函数</span></span><br><span class="line">killTomcat()</span><br><span class="line">&#123;</span><br><span class="line">    pid=`ps -ef|grep tomcat|grep java|awk <span class="string">'&#123;print $2&#125;'</span>`</span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"tomcat Id list :<span class="variable">$pid</span>"</span></span><br><span class="line">    <span class="keyword">if</span> [ <span class="string">"<span class="variable">$pid</span>"</span> = <span class="string">""</span> ]</span><br><span class="line">    <span class="keyword">then</span></span><br><span class="line">      <span class="built_in">echo</span> <span class="string">"no tomcat pid alive"</span></span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">      <span class="built_in">kill</span> -9 <span class="variable">$pid</span></span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line">    <span class="comment">#上面注释的或者下面的</span></span><br><span class="line">    <span class="comment">#cd $TOMCAT_APP_PATH/bin</span></span><br><span class="line">    <span class="comment">#sh shutdown.sh</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">cd</span> <span class="variable">$PROJ_PATH</span>/workspace/springboot-test-gitlab2/springboot</span><br><span class="line">mvn clean install</span><br><span class="line"></span><br><span class="line"><span class="comment"># 停tomcat</span></span><br><span class="line">killTomcat</span><br><span class="line"></span><br><span class="line"><span class="comment"># 删除原有工程</span></span><br><span class="line"><span class="comment">#rm -rf $TOMCAT_APP_PATH/webapps/ROOT</span></span><br><span class="line"><span class="comment">#rm -f $TOMCAT_APP_PATH/webapps/ROOT.war</span></span><br><span class="line">rm -f <span class="variable">$TOMCAT_APP_PATH</span>/webapps/springboot-test-gitlab.war</span><br><span class="line"></span><br><span class="line"><span class="comment"># 复制新的工程到tomcat上</span></span><br><span class="line">cp <span class="variable">$PROJ_PATH</span>/workspace/springboot-test-gitlab2/springboot/target/springboot-test-gitlab-0.0.1-SNAPSHOT.war <span class="variable">$TOMCAT_APP_PATH</span>/webapps/</span><br><span class="line"></span><br><span class="line"><span class="built_in">cd</span> <span class="variable">$TOMCAT_APP_PATH</span>/webapps/</span><br><span class="line">mv springboot-test-gitlab-0.0.1-SNAPSHOT.war springboot-test-gitlab.war</span><br><span class="line"></span><br><span class="line"><span class="comment"># 启动Tomcat</span></span><br><span class="line"><span class="built_in">cd</span> <span class="variable">$TOMCAT_APP_PATH</span>/</span><br><span class="line">sh bin/startup.sh</span><br></pre></td></tr></table></figure><p><strong>创建一个任务</strong><br>名称：springboot-test-gitlab2<br>类型: 一个自由风格的任务<br><img src="https://upload-images.jianshu.io/upload_images/15645795-faa9a49c60e854d5.png" alt="gitlab2_2.png"></p><p>源码管理：<br>gitlab配置节点的ssh公钥 ，配置参考：[SSH 证书生成(Linux、windows).md](其它/SSH 证书生成(Linux、windows).md) 中的 “二、Linux生成证书–&gt;3.证书使用-例如：配置gitlab”。<br><img src="https://upload-images.jianshu.io/upload_images/15645795-b05fc473902fa20d.png" alt="gitlab2_1.png"></p><p>构建触发器配置:<br>请参考:<a href="https://www.jianshu.com/p/7f79446357b5" target="_blank" rel="noopener">jenkins构建触发器配置</a>中的_代码提交—&gt;gitlab通知jenkins构建.<br><img src="https://upload-images.jianshu.io/upload_images/15645795-745a11c796b45b3a.png" alt="gitlab2_5.png"></p><p>构建配置:<br><img src="https://upload-images.jianshu.io/upload_images/15645795-35834b4111c55782.png" alt="gitlab2_3.png"></p><blockquote><p>BUILD_ID=DONTKILLME<br>. /etc/profile<br>export PROJ_PATH=/root/.jenkins<br>export TOMCAT_APP_PATH=/usr/local/apache-tomcat-8.5.46<br>sh $PROJ_PATH/workspace/springboot-test-gitlab2/springboot/deploy.sh</p></blockquote><p>保存-&gt;执行构建<br>执行构建结果：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">Started by GitLab push by zhengja</span><br><span class="line">Started by user zhengja</span><br><span class="line">Rebuilds build #7</span><br><span class="line">Running as SYSTEM</span><br><span class="line">Building remotely on Linux_127 in workspace &#x2F;root&#x2F;.jenkins&#x2F;workspace&#x2F;springboot-test-gitlab2</span><br><span class="line">No credentials specified</span><br><span class="line"> &gt; git rev-parse --is-inside-work-tree # timeout&#x3D;10</span><br><span class="line">Fetching changes from the remote Git repository</span><br><span class="line"> &gt; git config remote.origin.url ssh:&#x2F;&#x2F;git@elbgit-1200450932.cn-northwest-1.elb.amazonaws.com.cn:5337&#x2F;zhengja&#x2F;springboot-test-gitlab.git # timeout&#x3D;10</span><br><span class="line">Fetching upstream changes from ssh:&#x2F;&#x2F;git@elbgit-1200450932.cn-northwest-1.elb.amazonaws.com.cn:5337&#x2F;zhengja&#x2F;springboot-test-gitlab.git</span><br><span class="line"> &gt; git --version # timeout&#x3D;10</span><br><span class="line"> &gt; git fetch --tags --progress ssh:&#x2F;&#x2F;git@elbgit-1200450932.cn-northwest-1.elb.amazonaws.com.cn:5337&#x2F;zhengja&#x2F;springboot-test-gitlab.git +refs&#x2F;heads&#x2F;*:refs&#x2F;remotes&#x2F;origin&#x2F;*</span><br><span class="line">...........</span><br><span class="line">.........</span><br><span class="line">..........</span><br><span class="line">09:28:22.884 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: &#123;spring.jmx.enabled&#x3D;false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper&#x3D;true, server.port&#x3D;-1&#125;</span><br><span class="line"></span><br><span class="line">  .   ____          _            __ _ _</span><br><span class="line"> &#x2F;\\ &#x2F; ___&#39;_ __ _ _(_)_ __  __ _ \ \ \ \</span><br><span class="line">( ( )\___ | &#39;_ | &#39;_| | &#39;_ \&#x2F; _&#96; | \ \ \ \</span><br><span class="line"> \\&#x2F;  ___)| |_)| | | | | || (_| |  ) ) ) )</span><br><span class="line">  &#39;  |____| .__|_| |_|_| |_\__, | &#x2F; &#x2F; &#x2F; &#x2F;</span><br><span class="line"> &#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;|_|&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;|___&#x2F;&#x3D;&#x2F;_&#x2F;_&#x2F;_&#x2F;</span><br><span class="line"> :: Spring Boot ::        (v2.1.8.RELEASE)</span><br><span class="line"></span><br><span class="line">2019-09-30 09:28:23.541  INFO 29490 --- [           main] d.s.SpringbootTestGithubApplicationTests : Starting SpringbootTestGithubApplicationTests on VM_0_6_centos with PID 29490 (started by root in &#x2F;root&#x2F;.jenkins&#x2F;workspace&#x2F;springboot-test-gitlab2&#x2F;springboot)</span><br><span class="line">................</span><br><span class="line">............</span><br><span class="line">........</span><br><span class="line">[INFO] Installing &#x2F;root&#x2F;.jenkins&#x2F;workspace&#x2F;springboot-test-gitlab2&#x2F;springboot&#x2F;pom.xml to &#x2F;root&#x2F;.m2&#x2F;repository&#x2F;com&#x2F;dist&#x2F;springboot-test-gitlab&#x2F;0.0.1-SNAPSHOT&#x2F;springboot-test-gitlab-0.0.1-SNAPSHOT.pom</span><br><span class="line">[INFO] ------------------------------------------------------------------------</span><br><span class="line">[INFO] BUILD SUCCESS</span><br><span class="line">[INFO] ------------------------------------------------------------------------</span><br><span class="line">[INFO] Total time:  16.105 s</span><br><span class="line">[INFO] Finished at: 2019-09-30T09:28:31+08:00</span><br><span class="line">[INFO] ------------------------------------------------------------------------</span><br><span class="line">tomcat Id list :29272</span><br><span class="line">Tomcat started.</span><br><span class="line">Finished: SUCCESS</span><br></pre></td></tr></table></figure><p>访问： <a href="http://129.204.207.127:8090/springboot-test-gitlab/" target="_blank" rel="noopener">http://129.204.207.127:8090/springboot-test-gitlab/</a></p><p>html页面显示：</p><blockquote><p>进入首页<br>测试自动构建是否成功<br>测试gitlab–&gt;通知jenkins自动构建</p></blockquote><p>到此 ，项目的自动部署及发布完成!</p><h2 id="五、配置邮箱通知"><a href="#五、配置邮箱通知" class="headerlink" title="五、配置邮箱通知"></a>五、配置邮箱通知</h2><p><strong>目的：代码上传-&gt;gitlab通知-&gt;jenkins服务器执行构建-&gt;远程应用服务器git下拉-&gt;远程应用服务器maven打包-&gt;发送到远程应用服务器的tomcat-&gt;发布-&gt;邮箱通知</strong></p><p>参考 ：<a href="https://www.jianshu.com/p/ddfe09af036a" target="_blank" rel="noopener">jenkins 邮箱通知配置</a></p></div><div class="popular-posts-header"><p style="font-size:18px;color:red;margin:0 0 5px 0">相关文章推荐：</p></div><ul class="popular-posts"><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\2178418947.html" rel="bookmark">Jenkins-节点slave配置</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\2299959189.html" rel="bookmark">Jenkins-内存优化问题</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\731062347.html" rel="bookmark">Linux节点环境搭建</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\4040030628.html" rel="bookmark">SSH-证书生成（Linux、Windows）</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\2673893071.html" rel="bookmark">Windows版-Jenkins-自动化部署</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\3462919382.html" rel="bookmark">jenkins-使用节点部署项目</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\2023982305.html" rel="bookmark">jenkins-更改工作空间</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\2573215680.html" rel="bookmark">jenkins-邮箱通知配置</a></div></li></ul><div><div style="text-align:center;color:#ccc;font-size:14px">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div></div><div class="reward-container"><div><p style="font-size:14px;color:#34495e;margin:0 0 5px 0">赞赏一下吧～ 还可以关注公众号订阅最新内容</p></div><button disable="enable" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">打赏</button><div id="qr" style="display:none"><div style="display:inline-block"><img src="/my-images/WeChat.png" alt="宇宙小神特别萌 微信支付"><p>微信支付</p></div><div style="display:inline-block"><img src="/my-images/Alipay.png" alt="宇宙小神特别萌 支付宝"><p>支付宝</p></div></div></div><footer class="post-footer"><div class="post-tags"><a href="/tags/Jenkins/" rel="tag"><i class="fa fa-tag"></i> Jenkins</a></div><div class="post-nav"><div class="post-nav-item"><a href="/posts/731062347.html" rel="prev" title="Linux节点环境搭建"><i class="fa fa-chevron-left"></i> Linux节点环境搭建</a></div><div class="post-nav-item"><a href="/posts/2299959189.html" rel="next" title="Jenkins-内存优化问题">Jenkins-内存优化问题 <i class="fa fa-chevron-right"></i></a></div></div></footer></article></div></div><div class="comments" id="valine-comments"></div><script>window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }</script></div><div class="toggle sidebar-toggle"><span class="toggle-line toggle-line-first"></span> <span class="toggle-line toggle-line-middle"></span> <span class="toggle-line toggle-line-last"></span></div><aside class="sidebar"><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc">文章目录</li><li class="sidebar-nav-overview">站点概览</li></ul><div class="post-toc-wrap sidebar-panel"><div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、部署jenkins服务器-Linux1"><span class="nav-text">一、部署jenkins服务器(Linux1)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1、安装jdk1-8"><span class="nav-text">1、安装jdk1.8</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2、安装jenkins"><span class="nav-text">2、安装jenkins</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1jenkins-插件安装-推荐"><span class="nav-text">2.1jenkins 插件安装(推荐)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2jenkins-基础配置"><span class="nav-text">2.2jenkins 基础配置</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、部署应用服务器-Linux2"><span class="nav-text">二、部署应用服务器(Linux2)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-，开启ssh"><span class="nav-text">1 ，开启ssh</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-，关闭防火墙-内网环境相对安全"><span class="nav-text">2 ，关闭防火墙(内网环境相对安全)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-，安装-jdk"><span class="nav-text">2 ，安装 jdk</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-方式一：普通安装方式：-下载慢"><span class="nav-text">2.1 方式一：普通安装方式：(下载慢)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-方式二：安装指定版本：java1-8（下载慢）"><span class="nav-text">2.2 方式二：安装指定版本：java1.8（下载慢）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-方式三：下载jdk1-8上传linux服务器-安装快-推荐"><span class="nav-text">2.3 方式三：下载jdk1.8上传linux服务器(安装快-推荐)</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3、安装-git"><span class="nav-text">3、安装 git</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#方式一：git安装（旧版本）"><span class="nav-text">方式一：git安装（旧版本）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#方式二：gti安装-最新版本—推荐"><span class="nav-text">方式二：gti安装(最新版本—推荐)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#生成ssh密钥-配置git"><span class="nav-text">生成ssh密钥 配置git</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4、安装-maven"><span class="nav-text">4、安装 maven</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5、安装-tomcat"><span class="nav-text">5、安装 tomcat</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、jenkins节点Slave配置"><span class="nav-text">三、jenkins节点Slave配置</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1、Linux-的-Slave机器设置"><span class="nav-text">1、Linux 的 Slave机器设置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2、jenkins配置节点slave凭证"><span class="nav-text">2、jenkins配置节点slave凭证</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#四、创建一个任务-使用节点环境"><span class="nav-text">四、创建一个任务(使用节点环境)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#五、配置邮箱通知"><span class="nav-text">五、配置邮箱通知</span></a></li></ol></div></div><div class="site-overview-wrap sidebar-panel"><div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person"><img class="site-author-image" itemprop="image" alt="宇宙小神特别萌" src="/my-images/avatar.gif"><p class="site-author-name" itemprop="name">宇宙小神特别萌</p><div class="site-description" itemprop="description">人生就是一次幸运的旅行！</div></div><div class="site-state-wrap motion-element"><nav class="site-state"><div class="site-state-item site-state-posts"><a href="/archives/"><span class="site-state-item-count">116</span> <span class="site-state-item-name">文章</span></a></div><div class="site-state-item site-state-tags"><a href="/tags/"><span class="site-state-item-count">27</span> <span class="site-state-item-name">标签</span></a></div></nav></div><div class="links-of-author motion-element"><span class="links-of-author-item"><a href="https://github.com/zhengjiaao" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zhengjiaao" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a> </span><span class="links-of-author-item"><a href="https://www.jianshu.com/u/70d69269bd09" title="简书 → https:&#x2F;&#x2F;www.jianshu.com&#x2F;u&#x2F;70d69269bd09" rel="noopener" target="_blank"><i class="fa fa-fw fa-book"></i>简书</a> </span><span class="links-of-author-item"><a href="/atom.xml" title="RSS → &#x2F;atom.xml"><i class="fa fa-fw fa-rss"></i>RSS</a></span></div><div class="links-of-blogroll motion-element"><div class="links-of-blogroll-title"><i class="fa fa-fw fa-link"></i> 推荐阅读</div><ul class="links-of-blogroll-list"><li class="links-of-blogroll-item"><a href="https://github.com/spring-projects" title="https:&#x2F;&#x2F;github.com&#x2F;spring-projects" rel="noopener" target="_blank">spring-projects</a></li><li class="links-of-blogroll-item"><a href="http://www.alloyteam.com/nav/" title="http:&#x2F;&#x2F;www.alloyteam.com&#x2F;nav&#x2F;" rel="noopener" target="_blank">Web前端导航</a></li><li class="links-of-blogroll-item"><a href="http://www.chuangzaoshi.com/code" title="http:&#x2F;&#x2F;www.chuangzaoshi.com&#x2F;code" rel="noopener" target="_blank">创造狮导航</a></li></ul></div></div></div></aside><div id="sidebar-dimmer"></div></div></main><footer class="footer"><div class="footer-inner"><div class="copyright">&copy; <span itemprop="copyrightYear">2020</span> <span class="with-love"><i class="fa fa-heart"></i> </span><span class="author" itemprop="copyrightHolder">宇宙小神特别萌</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-area-chart"></i> </span><span title="站点总字数">1.2m</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-coffee"></i> </span><span title="站点阅读时长">17:41</span></div><div class="busuanzi-count"><script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span class="post-meta-item" id="busuanzi_container_site_uv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-user"></i> </span><span class="site-uv" title="总访客量"><span id="busuanzi_value_site_uv"></span> </span></span><span class="post-meta-divider">|</span> <span class="post-meta-item" id="busuanzi_container_site_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="site-pv" title="总访问量"><span id="busuanzi_value_site_pv"></span></span></span></div></div></footer></div><script src="//cdn.jsdelivr.net/npm/animejs@3.1.0/lib/anime.min.js"></script><script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script><script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.ui.min.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script>!function(){var t=document.createElement("script"),e=window.location.protocol.split(":")[0];t.src="https"===e?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s)}()</script><script src="/js/local-search.js"></script><script>NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//cdnjs.cloudflare.com/ajax/libs/valine/1.3.10/Valine.min.js', () => {
    <!--var GUEST = ['nick', 'mail', 'link'];-->
    var GUEST = ['nick', 'mail'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el: '#valine-comments',
      verify: false,
      notify: false,
      appId: 'OuyHeA0XGL8hK4vgbqL0iERx-gzGzoHsz',
      appKey: 'L58VglKmWULcGK2W2AN7kWzM',
      placeholder: "留下邮箱，有回复时你将收到提醒，邮箱不会被公开。",
      avatar: 'wavatar',
      meta: guest,
      pageSize: '10' || 10,
      visitor: true,
      lang: 'zh-cn' || 'zh-cn',
      path: location.pathname,
      recordIP: true,
      serverURLs: ''
    });
  }, window.Valine);
});</script><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({pluginRootPath:"live2dw/",pluginJsPath:"lib/",pluginModelPath:"assets/",tagMode:!1,model:{jsonPath:"/live2dw/assets/wanko.model.json"},display:{position:"right",width:150,height:300},mobile:{show:!1},log:!1})</script></body><script type="text/javascript" src="/js/src/activetitle.js"></script></html><!-- rebuild by neat -->